package com.example.sellersale.controller;

import com.example.sellersale.entity.CartInfo;
import com.example.sellersale.entity.Order;
import com.example.sellersale.server.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class OrderController {
    @Autowired
    private OrderService orderService;
    /**
     * 实现生成用户订单功能
     * @param cartInfos
     * @return
     */
    @PostMapping("/addOrders")
    public Boolean order(@RequestBody List<CartInfo> cartInfos){
        System.out.println("====前端传递过来的购物车列表=====");
        System.out.println(cartInfos);
        return  orderService.addOrders(cartInfos);
    }

    @GetMapping("/userOrders")
    public List<Order>  ordersSelect(String uId){
        List<Order> orders = orderService.selectOneOrder(uId);
        return orders;
    }
    //获取所有的订单信息
    @GetMapping("/allUserOrder")
    public List<Order> allOrder(){
        List<Order> orders = orderService.allUserOrder();
        return orders;
    }
    /**
     * 活动指定时间内的订单信息
     * @param time
     * @return
     */
    @GetMapping("/timeOrder")
    public List<Order> speciallyTimeOrder(String time){
        return orderService.speciallyTimeOrder(time);
    }

    @PostMapping("/editStatus")
    public boolean updateOrderStatus(String oId,String gId,String status){
        return orderService.updateOrderStatus(oId,gId,status);
    }
}
